<%@ page import="java.util.Map"%>
<%@ page import="net.sf.json.JSONObject"%>
<%@ page import="Business.FinalAll"%>
<%@ page contentType="application/json;charset=UTF-8"%>
<%
Map<String , Object> cookies = Business.Cookie.getCookieList(request.getCookies());
Object cookieObj = cookies.get("cookie");
Object nickNameObj = request.getAttribute("nickName");
Object avatarUrlObj = request.getAttribute("avatarUrl");
Object openidObj = request.getAttribute("openid");
boolean ObjErr = cookieObj == null || nickNameObj == null || avatarUrlObj == null || openidObj == null;
if (ObjErr){
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("errMsg","参数异常！");
    out.println(jsonObject);
    return;
}
String cookie = cookieObj.toString();
String nickName = nickNameObj.toString();
String avatarUrl = avatarUrlObj.toString();
String openid = openidObj.toString();
boolean strErr = cookie.length() <= 0 || nickName.length() <= 0 || avatarUrl.length() <=0 || openid.length() <= 0;
if (strErr){
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("errMsg","参数异常！2");
    out.println(jsonObject);
    return;
}//参数检查正确
Map<String , Object> userinfo = Mysql.Query.getUser(openid);
if (userinfo == null){
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("errMsg","用户状态异常！2");
    out.println(jsonObject);
    return;
}
String mysqlCookie = (String) userinfo.get("cookie");
if (!cookie.equals(mysqlCookie)){//不相同
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("errMsg","用户状态异常！");
    out.println(jsonObject);
    return;
}//cookie检查完成
if(!Mysql.Update.updUserInfo(openid,cookie,nickName,avatarUrl)){//更新用户信息异常
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("errMsg","运行时异常！1");
    out.println(jsonObject);
    return;
}
Business.Cookie.removeCookieAll(request.getCookies() , response);//清除所有cookie
Cookie cookie1 = new Cookie("cookie",cookie);
cookie1.setMaxAge(60 * 60 * 24 * FinalAll.OutTimeCookieDay);
cookie1.setPath("/");
response.addCookie(cookie1);//返回cookie
JSONObject reJson = new JSONObject();
reJson.put("errMsg",0);
out.println(reJson);
%>